<?php
namespace app\admin\model;

use think\Model;
use think\Db;

/**
 * 错误对照管理模型
 * @package app\admin\model
 */
class ErrorComparisonM extends Model
{
    protected $table = 'bus_code_mapping';

    public function getAllData($request)
    {
        $data = $this::field('*');

        if(!empty($request['code'])) {

            $data = $data->where('code', 'like', '%'. $request['code'] . '%');
        }

        $data = $data->order('id asc')->paginate($request['limit'], false, ['query' => $request]);

        return $data;
    }

    public function addOne($data)
    {
        $model = new ErrorComparisonM;

        $model->data([
            'code' => $data['code'],
            'desc' => $data['desc']
        ]);
        return $model->save();
    }

    public function updateOne($data)
    {
        $model = new ErrorComparisonM;

        return $model->save($data, ['id' => $data['id']]);
    }

    public function delOne($data)
    {
        $model = ErrorComparisonM::get($data['id']);
        return $model->delete();
    }

}